﻿using System;
using System.Collections.Generic;
using System.Text;

using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Index;

namespace ActiveDocument.SearchEngine
{
    public static class SearchEngineIndex
    {
        private static Analyzer analyzer;
        private static IndexWriter writer;
        private static IndexSearcher searcher;

        public static Analyzer Analyzer
        {
            get
            {
                if (analyzer == null)
                    analyzer = new StandardAnalyzer();
                return analyzer;
            }
        }
        public static IndexWriter Writer
        {
            get
            {
                if (writer == null)
                    writer = new IndexWriter(System.AppDomain.CurrentDomain.BaseDirectory + "/App_Data", analyzer, true);
                return writer;
            }
        }
        public static IndexSearcher Searcher
        {
            get
            {
                if (searcher == null)
                    searcher = new IndexSearcher(FSDirectory.GetDirectory(System.AppDomain.CurrentDomain.BaseDirectory + "/App_Data", false));
                return searcher;
            }
        }


        public static void Add(Document d)
        {
            Writer.AddDocument(d);
            writer.Optimize();
        }

        public static void Update(Document d)
        {

        }

        public static void Delete(Document d)
        {

        }
    }
}
